package com.campus.controller;

import com.campus.pojo.SysArea;
import com.campus.service.AreaService;
import com.campus.service.Impl.AreaServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/area")
public class AreaController {
    @Autowired
    AreaService service;

    @RequestMapping("/getShengAreaList")
    @ResponseBody
    public Map<String,Object> getShengAreaAreaList(SysArea sysArea){
        sysArea.setType("1");//1 为省
        List<SysArea> list = service.getAreaList(sysArea);//查询所有省
        int count = 0;
        if (list != null && list.size()>0)
            count = list.size();
        Map<String,Object>result = new HashMap<>();
        result.put("count",count);
        result.put("CityList", list);
        return result;
    }

    @ResponseBody
    @RequestMapping("/getShiAreaList")
    public Map<String,Object> getShiAreaList(SysArea sysArea){
        sysArea.setType("2");//2 为市
        List<SysArea> list = service.getAreaList(sysArea);//查询所有市
        int count = 0;
        if (list != null && list.size()>0)
            count = list.size();
        Map<String,Object>result = new HashMap<>();
        result.put("count",count);
        result.put("CityList", list);
        return result;
    }

    @ResponseBody
    @RequestMapping("/getXianAreaList")
    public Map<String,Object>getXianAreaList(SysArea sysArea){
        sysArea.setType("3");//3 为院校
        List<SysArea> list = service.getAreaList(sysArea);//查询所有院校
        int count = 0;
        if (list != null && list.size()>0)
            count = list.size();
        Map<String,Object>result = new HashMap<>();
        result.put("count",count);
        result.put("CityList", list);
        return result;
    }
}
